package com.lagou.service.Impl;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.lagou.Annotion.MyService;
import com.lagou.mapper.UserMapper;
import com.lagou.pojo.User;
import com.lagou.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Authther: mrwu
 * @date:2021/3/21-03
 * @Description:com.lagou.service.Impl
 */
@MyService
public class UserServiceImpl implements UserService {
    private static UserMapper userMapper ;
    static {
        try {
            InputStream inputStream = Resources.getResourceAsStream("MybatisConfig.xml");
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(inputStream).openSession();
            userMapper = sqlSession.getMapper(UserMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public User findByUserName(String name) {
        List<User> byUserName = userMapper.findByUserName(name);
        if (byUserName.size()>0){
            return byUserName.get(0);
        }
        System.out.println(byUserName);
        return null;
    }

}
